package spring.bean;

import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @Date 2021/5/7 16:04
 * @Author WangLinBao
 * @Description
 */
//实现所有bean级生命周期接口
@Setter @Getter
public class Car implements BeanNameAware, BeanFactoryAware, InitializingBean, DisposableBean {
    private String brand;
    private String color;
    private int maxSpeed;

    private BeanFactory beanFactory;

    private String beanName;


    /**
     * BeanFactoryAware接口方法
     * @param beanFactory
     * @throws BeansException
     */
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("调用BeanFactoryAware的setBeanFactory().");
        this.beanFactory = beanFactory;
    }

    /**
     * BeanNameAware 接口方法
     * @param beanName
     */
    @Override
    public void setBeanName(String beanName) {
        System.out.println("调用BeanNameAware的setBeanName()方法");
        this.beanName = beanName;
    }
    /**
     * DisposableBean 接口方法
     * @throws Exception
     */
    @Override
    public void destroy() throws Exception {
        System.out.println("调用DisposableBean 的 destroy()方法");
    }
    /**
     * InitializingBean 接口方法
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("调用 InitializingBean 的 afterPropertiesSet()方法");
    }
    public void myInit(){
        System.out.println("调用 myInit()方法 将maxSpeed设置为240");
        this.maxSpeed = 240;
    }
    public void myDestroy(){
        System.out.println("调用 myDestroy()方法");
    }

    public Car(){
        System.out.println("调用 car 的构造器");
    }

    public void setBrand(String brand){
        System.out.println("调用setBrand()设置属性");
        this.brand = brand;
    }

    public void introduce(){
        System.out.println("brand:"+brand+ ";color:"+color+";maxSpeed:"+maxSpeed+";");
    }

    public static void main(String[] args) {
        Integer a = 600;
        boolean b = 600==a;
        System.out.println("b = " + b);
    }
}
